<?php
/**
 *
 * @author Strawberry🍓
 * @date 2021-05-21 4:08 下午
 *
 */

namespace app\common\model\tang;


use app\common\impl\Comm;
use app\common\model\CommonBaseModel;

class MerchantReadingLog extends CommonBaseModel implements Comm
{

    public function getAdminPageData($param = [], $order = 'id desc')
    {
        // TODO: Implement getAdminPageData() method.
        $where=[];
        if (isset($param['type']) && !empty($param['type'])) {
            $where[] = ["type", "=", $param["type"]];
        }
        if (isset($param["merchant_id"]) && !empty($param['merchant_id'])) {
            $where[] = ["merchant_id", "=", $param['merchant_id']];
        }
        if (isset($param["in_type"]) && !empty($param['in_type'])) {
            $where[] = ["in_type", "=", $param['in_type']];
        }
        if (isset($param["new_merchant_id"]) && !empty($param['new_merchant_id'])) {
            $where[] = ["new_merchant_id", "=", $param['new_merchant_id']];
        }
        if (isset($param['pointId']) && !empty($param['pointId'])) {
            $where[] = ["pointId", "like","%{$param['pointId']}%"];
        }
        $data = self::where($where)->with(['oldmchants','newmerchants'])->order('id desc')->page(PAGE)->limit(LIMIT)->select()->toArray();
        $count = self::where($where)->count("id");
        return parent::ajaxResult($data, $count);
    }

    public function delById($id)
    {
        // TODO: Implement delById() method.
    }

    public function doAll($data)
    {
        // TODO: Implement doAll() method.
        return parent::doAllData($data);
    }
    public function oldmchants()
    {
        return $this->hasOne(Merchant::class,'id','merchant_id');
    }
    public function newmerchants()
    {
        return $this->hasOne(Merchant::class,'id','new_merchant_id');
    }
    public function watch()
    {
        return $this->hasOne(WatchMaintain::class,'pointId','pointId')->bind([
            'is_sole'=>'is_sole'
        ]);
    }
}